Assorted fixes: SilenceErrors, input validation, tests, and hardening#73
Merged
Merged
Conversation
Add Config.newIMSClient() that wraps httpClient() + ims.NewClient() into a single call. Replaces identical 8-line boilerplate across all 13 IMS operation methods.
… and hardening - Move SilenceErrors to root command, remove from 21 leaf commands (N17) - Add input validation for AuthorizeService and AuthorizeClientCredentials (6.2.3) - Save/restore browser.Stdout around OpenURL call (6.2.5) - Add defer listener.Close() in OAuth flow (N14) - Reject multiple tokens in resolveToken() (6.1.8) - Default version variable to "dev" for local builds (N16) - Add unit tests for all validators (43) - Add unicode/special char tests for pretty JSON (44) - Update CLAUDE.md with completed items
Replace 4 nearly-identical files in each of cmd/validate/ and cmd/invalidate/ with a single file using a factory pattern. Public API unchanged.
Remove the RegisterURL config field and --url flag from the dcr register command. The registration endpoint is now derived from the IMS base URL (persistent --url/-U flag) by appending /ims/register.
- -p always means --clientSecret (was -s in authz jwt and invalidate serviceToken) - -s always means --scopes (no longer overloaded) - -a always means --*ApiVersion (no longer overloaded) - --account gets -A, --authorizationCode gets -x, --cascading gets -C, --authSrc gets -A
Remove PKCE field from Config — it was not user configuration but a command-level decision. The pkce command now calls AuthorizeUserPKCE() directly instead of mutating the shared Config pointer.
…ON, URL slash
- Zero private key bytes after use in JWT exchange to prevent key material
lingering in memory until GC (6.1.7)
- Add port validation to validateAuthorizeUserConfig, remove defaultPort
fallback so the ims package validates its own parameters (N10)
- Replace map[string]interface{} with anonymous struct in refresh command
for deterministic JSON field order and better performance (N11)
- Trim trailing slash from IMS URL before building JWT claim keys to
prevent double-slash in metascope URIs (6.2.10)
- Standardize orgs API version error message to match profile style (6.2.12)
- Document PersistentPreRunE override risk in README.md (N7)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The Expires field was set in jwt_exchange.go, exchange.go, and refresh.go but never read by any caller. The calculations were also wrong: duration * duration produces nanoseconds-squared (overflow), and refresh.go used time.Second while the others used time.Millisecond. Remove the field entirely rather than fixing dead code. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
andresbott
approved these changes
Feb 27, 2026
Remove dead TokenInfo.Expires field and broken calculations
Miscellaneous hardening: key zeroing, port validation, struct JSON
Split AuthorizeUser into AuthorizeUser and AuthorizeUserPKCE
Standardize flag shorthands across all commands
Use IMS base URL for DCR registration
…idate Deduplicate validate and invalidate subcommands
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
SilenceErrors: trueto root command, remove from 21 leaf commandsAuthorizeServiceandAuthorizeClientCredentialsbrowser.StdoutaroundOpenURLto avoid side effectsdefer listener.Close()in OAuth flow to prevent listener leak on panicresolveToken()— returns error instead of silently picking first matchversionvariable to"dev"so local builds show a version stringnewIMSClient()helper, deduplicate 13 call sitesresolveToken(), andvalidateURL()